﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ShivamEMR.Model.Domain.ContactsDomain;
using ShivamEMR.Model.Domain.CommonDomain;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;

namespace ShivamEMR.Model.Domain.PersonDomain
{
    [Description("Holds the Person demographicdata with relationships with details tables")]
 public   class Person
    {

        public Person()
        {
            ID = Guid.NewGuid();
            DateOfBirth = DateTime.Now;
        }

        #region Properties 
        [Description("Unique Identifire of person for the system")]       
        public Guid ID { get; set; }
        [Description("Person Code Depends on coding system of the organization")]
        public string Code { get; set; }
        [Display( Name="Title", Description= "Title of the person (Mr,Dr,Mrs,Ms etc")]
        [Required(ErrorMessage="Person Title is required")]
        [StringLength(15)]
        public string Title { get; set; }
        [Description("First name of the person")]
        [StringLength(50)]
        [Required]
        public string FirstName { get; set; }
        [Description("Middle name of the person")]
        [StringLength(50)]
        [Required]
        public string MiddleName { get; set; }
        [Description("Last name of the person")]
        [StringLength(50)]
        [Required]
        public string LastName { get; set; }
        [Description("Alternate first name of the person")]
        [StringLength(50)]
        public string AltFirstName { get; set; }
        [Description("Alternate middle name of the person")]
        [StringLength(50)]
        public string AltMiddleName { get; set; }
        [Description("Alternate last name of the person")]
        [StringLength(50)]
        public string AltLastName { get; set; }
        [Description("Date of birth of the person, may hold time also")]
        [Required]
        [DataType(DataType.Date)]
        public DateTime DateOfBirth { get; set; }
        [Description("Barcode of the person after registration generated")]
        [StringLength(50)]
        public string Barcode { get; set; }
        #endregion

        #region ForeignKeyProperties
        public int SexID { get; set; }
         
        public Nullable<int> MaritalSatusID { get; set; }
        public Nullable<Guid> PictureID { get; set; }
        [ForeignKey("Account")]  
        public Nullable<Guid> PersonAccountID { get; set; }
        public int PersonStatusID { get; set; }
        #endregion

        #region NavigationalProperties
        [Description("FK gender/sex of the person")]       
        [ForeignKey("SexID")]
        public virtual Sex Sex { get; set; }
        [Description("FK(MatitalStatus) marital status of the person")]
        [ForeignKey("MaritalSatusID")]
        public virtual MaritalStatus MaritalStatus { get; set; }
        [Description("FK(PersonPictures) picture of the person")]
        [ForeignKey("PictureID")]     
        public virtual PersonPicture Picture { get; set; }
        [Description("FK(Addresses) Addresses of the person")]
        public ICollection<Address> Addresses { get; set; }
        [Description("FK(Contacts) Contacts of the person")]
        public ICollection<Contact> Contacts { get; set; }
        [Description("FK(Nationalities) Citizenships of the person")]
        public ICollection<Nationality> CitizenShips { get; set; }
        [Description("FK(PersonInformations) other details of the person")]
        public virtual ICollection<PersonInformation> Informations { get; set; }
        [Description("FK(PersonAccounts) Financial account of the person")]             
        public virtual PersonAccount Account { get; set; }
        [Description("FK(Person Roles) Roles of the person in the system")]      
        public virtual ICollection<PersonRole> PersonRoles { get; set; }
        [Description("FK(PersonStatus) Current Status of the person")]      
        [ForeignKey("PersonStatusID")]
        public virtual PersonStatus PersonStatus { get; set; }
        [Description("FK(PersonGroups) Groups to which the person relates")]
        public virtual ICollection<PersonGroup> Groups { get; set; }
        [Description("FK(Documents) Documents and files of the person stored on the file system")]
        public virtual ICollection<Document> Documents { get; set; }

        public virtual ICollection<CRMDomain.Assignment> Assignments { get; set; }
        public virtual ICollection<CRMDomain.Interaction> InteractionsWith { get; set; }
        #endregion

        [NotMapped]
        public string FullName
        {
            get
            {
                return Title + " " + FirstName + " " + MiddleName + " " + LastName;
            }
        }
       
     
    }
}
